<template>
	<view>
		<view style="height: 1px;"></view>
		<image class="icon-img" src="../../static/img/s2.png" mode=""></image>
		<view class="uni-title">绑定登录</view>
		<input placeholder="请输入账号" type="text" v-model="name" />
		<input placeholder="请输入密码" type="password" v-model="password" />
		
		<button class="login" @click="login()">确定</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			name: '',
			password: '',
		};
	},
	onLoad() {
		
	},
	methods: {
		login() {
			//绑定
			var that = this;
			if(!that.name){
				uni.showToast({
					title: '账号不能为空',
					icon: 'none'
				});
				return
			}
			if(!that.password){
				uni.showToast({
					title: '密码不能为空',
					icon: 'none'
				});
				return
			}
			uni.showLoading({
				mask:false
			})
			uni.request({
				url: '/app/wechatApi/apiLogin',
				method: 'POST',
				data: {
					openid: uni.getStorageSync('openid'),
					username:that.name,
					password:that.password,
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						uni.hideLoading()
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration:2000
						});
					
						// 当前人部门id
						uni.setStorageSync('deptId', res.data.data.deptId);
						
						// 登录人员的身份
						for(let i=0 ;i<res.data.data.roleList.length;i++){
							if(res.data.data.roleList[i] == "1207491780946202626"){
								uni.setStorageSync('nowType','2')
							}else{
								uni.setStorageSync('nowType','1')
							}
						}
						// 前往首页
						setTimeout(function(){
							uni.reLaunch({
								url:'/pages/index/index'
							})
						},500)
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		}
	}
};
</script>

<style>
	page{
		background: #D6F7F7;
	}
/* 绑定登录 */
.icon-img{
	width: 135upx;
	height: 135upx;
	position: absolute;
	left: 50%;top: 15%;
	transform: translate(-50%,-50%);
}
.uni-title{
	margin:350upx 0 0 50upx ;
	font-size: 55upx;
	font-weight: 600;
}
input {
	font-size: 28upx;
	border-bottom: 1px solid #999999;
	padding: 25upx;
	margin: 0 55upx;
}
.login {
	background: #48E6E6;
	color: rgb(255, 255, 255);
	border-radius: 50upx;
	margin: 200upx 200upx 16upx 200upx;
	font-size: 30upx;
	padding: 20upx 0;
}

</style>
